package com.hzw.saas.web.admin.login.controller;

import com.hzw.saas.common.config.annotation.SysLog;
import com.hzw.saas.common.security.constants.SecurityConstants;
import com.hzw.saas.common.security.filter.AbstractLoginAuthenticationFilter;
import com.hzw.saas.common.security.pojo.dto.OAuth2AccessTokenDto;
import com.hzw.saas.common.security.pojo.param.LoginParam;
import io.swagger.annotations.*;
import lombok.AllArgsConstructor;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

/**
 * <p>登录控制器</p>
 * <p>目前只用来显示swagger接口，真正的登录控制参考{@link AbstractLoginAuthenticationFilter}</p>
 *
 * @author zzl
 * @since 12/22/2020
 */
@Controller
@RequestMapping
@AllArgsConstructor
@Api(tags = "系统用户登录")
public class LoginController {

    @SysLog(operation = "账号登录")
    @PostMapping(SecurityConstants.LOGIN_URI)
    @ApiOperation(value = "账号登录", notes = "处理用户登录请求")
    @ApiResponses({
            @ApiResponse(code= 200, message = "登录成功"),
            @ApiResponse(code= 400, message = "用户名或密码错误")
    })
    @ApiOperationSort(1)
    public OAuth2AccessTokenDto login(@RequestBody LoginParam login) {
        return new OAuth2AccessTokenDto();
    }

    @SysLog(operation = "登录注销")
    @PostMapping("/user/logout")
    @ApiOperation(value = "登录注销", notes = "注销用户登录")
    @ApiOperationSort(2)
    public ResponseEntity<String> logout() {
        return ResponseEntity.ok("登出成功");
    }

    @GetMapping("/user/hello")
    @ApiOperation(value = "登录测试", notes = "测试用户是否登录成功")
    @ApiOperationSort(3)
    public ResponseEntity<Object> hello() {
        return ResponseEntity.ok("hello world");
    }

}
